package com.kmxd.ams.app.event.log;

import cn.hutool.core.bean.BeanUtil;
import com.kmxd.ams.client.event.log.LoginLogEvent;
import com.kmxd.ams.client.logs.ILogLoginSvc;
import com.kmxd.ams.client.logs.dto.LogLoginAddDTO;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionalEventListener;

/**
 * description
 *
 * @author nickbi
 */
@Slf4j
@Component
@AllArgsConstructor
public class LogLoginListener {
  private final ILogLoginSvc logLoginSvc;

  @Async
  @TransactionalEventListener(fallbackExecution = true)
  public void login(LoginLogEvent event) {
    LogLoginAddDTO dto = BeanUtil.copyProperties(event, LogLoginAddDTO.class);
    logLoginSvc.add(dto);
  }
}
